package com.le.tester.imooc.masterJUC.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 描述：lock不会像synchronize在异常的时候释放锁，需要使用unlock释放锁
 */
public class MustUnlock {

    private static Lock lock = new ReentrantLock();

    public static void main(String[] args) {
        //不能被中断
        lock.lock();
        //尝试拿锁
        try {
            System.out.println(Thread.currentThread().getName() + " 开始执行任务");
        } finally {
            lock.unlock();
        }
    }
}
